<template>
  <div class="hello">
    <button @click="increase">增加</button>
    <button @click="decrease">减少</button>
  </div>
</template>

<script>
import { mapMutations, mapActions } from 'vuex'
//使用app.js统一管理变量名
import { INCREMENT, DECREMENT } from '@/store/mutations.types'
export default {
  name: 'HelloWorld',
  data () {
    return {}
  },
 methods:{
  //  ...mapMutations(['increment', 'decrement']),
   ...mapMutations([INCREMENT, DECREMENT]),


   ...mapActions(['myIncrease', 'myDecrease']),
  //  increase (){
  //     // 调用store中的mutations方法
  //   //  this.$store.commit('increment');
  //   // this.increase();
  //   this.myIncrease();
  //   },
  // decrease (){
  //     // 调用store中的mutations方法
  //     // this.$store.commit('decrement');
  //     // this.decrease();
  //     this.myDecrease();
  //   }

  async increase (){
      // 调用store中的mutations方法
     this.$store.commit(INCREMENT, 2);
    // this.increase();
    //  this.myIncrease({
    //    id: 123
    //  });
  //  const products =await this.myIncrease({
  //    id: 123
  //  }); 
  //  console.log(products)
    },
  decrease (){
      // 调用store中的mutations方法
      this.$store.commit(DECREMENT, 1);
      // this.decrease();
      // this.myDecrease();
    }
 }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
